#ifndef SERIALOP_H
#define SERIALOP_H

#include <QObject>
#include <QSerialPort>
#include <QThread>
#include <QDateTime>
#include <QtDebug>
#include <unistd.h>
#include <QMutex>
#include <QString>

#include "datasingleton.h"

#define GET_ALL_PARAMS "get_all"
#define RMAX "rmax="
#define MTH1 "mth1="
#define MTH2 "mth2="
#define MTH3 "mth3="
#define TEST_MODE "test_mode="
#define OUTPUT_MODE "output_mode="
#define TONS "tons="
#define UTONS "utons="
#define SAVE "save"

class SerialOp : public QObject
{
    Q_OBJECT
public:
    explicit SerialOp(QSerialPort* serial_ptr = nullptr, QObject *parent = nullptr);
    virtual ~SerialOp();

    void recv_data();
    void serail_recv_start();
    void serail_send_start(QByteArray data);
    void setSerailPtr(QSerialPort *serail_ptr);

    void setDefaultParms();

    QSerialPort *serail_ptr_;
    QThread serail_work_thread_;
    QByteArray buffer;
    QMutex serail_op_mtx_;

public slots:
    void openSerialPort(QString serail_str);
    void setSerailParams(qint32 baudRate, QSerialPort::DataBits dataBits,\
                         QSerialPort::Parity parity, QSerialPort::StopBits stopbits,\
                         QSerialPort::FlowControl fc);
    void closeSerialPort();
signals:
    void uartDataTextShow(QString str);
    void onSerialPortOpenResult(bool success);

};

#endif // SERIALOP_H
